home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / C de cerca / Codewarrior Lite / MacOS Support / Headers / ANSI Headers / ios < prev    next >
Text File  |  1995-12-29  |  5KB  |  198 lines

  1. // ios standard header
  2. #ifndef _IOS_
  3. #define _IOS_
  4. #include <exception>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8.  
  9. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  10. #pragma import on
  11. #endif
  12. #endif
  13.  
  14.   // I/O exception macros
  15. #if _CATCH_IO_EXCEPTIONS
  16.  #define _TRY_IO_BEGIN _TRY_BEGIN
  17.  #define _CATCH_IO_END _CATCH_ALL \
  18.  setstate(badbit); _RERAISE; _CATCH_END
  19.  #define _CATCH_IO_(x) _CATCH_ALL \
  20.  (x).setstate(ios::badbit); _RERAISE; _CATCH_END
  21. #else
  22.  #define _TRY_IO_BEGIN {
  23.  #define _CATCH_IO_END }
  24.  #define _CATCH_IO_(x) }
  25. #endif
  26. class ostream; class streambuf;
  27.   // class ios
  28. class ios {
  29. public:
  30.    // class failure
  31.  class failure : public xmsg {
  32.  public:
  33.   failure(const char *_X = 0, const char *_Y = 0,
  34.    const char *_Z = 0)
  35.    : xmsg(_X, _Y, _Z) {};
  36.   virtual ~failure();
  37.  protected:
  38.   virtual void do_raise();
  39.  };
  40.  enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
  41.   uppercase = 0x0004, showbase = 0x0008,
  42.   showpoint = 0x0010, showpos = 0x0020,
  43.   left = 0x0040, right = 0x0080, internal = 0x0100,
  44.   dec = 0x0200, oct = 0x0400, hex = 0x0800,
  45.   scientific = 0x1000, fixed = 0x2000,
  46.   adjustfield = 0x01c0, basefield = 0x0e00,
  47.   floatfield = 0x3000, _Fmtmask = 0x3fff, _Fmtzero = 0};
  48.  enum _Iostate {goodbit = 0x0, eofbit = 0x1,
  49.   failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
  50.  enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
  51.   app = 0x08, trunc = 0x10, binary = 0x20};
  52.  enum seekdir {beg = 0, cur = 1, end = 2};
  53.  _BITMASK(_Fmtflags, fmtflags);
  54.  _BITMASK(_Iostate, iostate);
  55.  _BITMASK(_Openmode, openmode);
  56.  typedef short io_state, open_mode, seek_dir;
  57.  enum _Uninitialized {_Noinit};
  58.    // class Init
  59.  class Init {
  60.  public:
  61.   Init();
  62.   ~Init();
  63.  private:
  64.   static int _Init_cnt;
  65.   };
  66.    // class _Iosarray
  67.  class _Iosarray {
  68.  public:
  69.   _Iosarray(int _Idx, _Iosarray *_Link = 0)
  70.    : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
  71.   _Iosarray *_Next;
  72.   int _Index;
  73.   long _Lo;
  74.   void *_Vp;
  75.   };
  76.  ios(streambuf *_S)
  77.   {init(_S); }
  78.  ios(const ios& _R)
  79.   {init(0), *this = _R; }
  80.  ios& operator=(const ios&);
  81.  virtual ~ios();
  82.  operator void *() const
  83.   {return (void *)(!*this ? 0 : this); }
  84.  _Bool operator!() const
  85.   {return (((int)_State
  86.    & ((int)failbit|(int)badbit)) != 0); }
  87.  ios& copyfmt(const ios&);
  88.  ostream *tie() const
  89.   {return (_Tiestr); }
  90.  ostream *tie(ostream *);
  91.  streambuf *rdbuf() const
  92.   {return (_Sb); }
  93.  streambuf *rdbuf(streambuf *);
  94.  iostate rdstate() const
  95.   {return (_State); }
  96.  void clear(iostate = goodbit);
  97.  void clear(io_state _St)
  98.   {clear((iostate)_St); }
  99.  void setstate(iostate _St)
  100.   {clear((iostate)((int)_State | (int)_St)); }
  101.  void setstate(io_state _St)
  102.   {setstate((iostate)_St); }
  103.  _Bool good() const
  104.   {return (_State == goodbit); }
  105.  _Bool eof() const
  106.   {return ((int)_State & (int)eofbit); }
  107.  _Bool fail() const
  108.   {return ((int)_State
  109.    & ((int)badbit | (int)failbit)); }
  110.  _Bool bad() const
  111.   {return ((int)_State & (int)badbit); }
  112.  iostate exceptions() const
  113.   {return (_Except); }
  114.  void exceptions(iostate);
  115.  void exceptions(io_state _St)
  116.   {exceptions((iostate)_St); }
  117.  fmtflags flags() const
  118.   {return (_Fmtfl); }
  119.  fmtflags flags(fmtflags);
  120.  fmtflags setf(fmtflags);
  121.  fmtflags setf(fmtflags, fmtflags);
  122.  void unsetf(fmtflags);
  123.  int fill() const
  124.   {return (_Fillch); }
  125.  int fill(int);
  126.  int precision() const
  127.   {return (_Prec); }
  128.  int precision(int);
  129.  int width() const
  130.   {return (_Wide); }
  131.  int width(int);
  132.  static int xalloc()
  133.   {return (_Index++); }
  134.  long& iword(int _Idx)
  135.   {return (_Findarr(_Idx)._Lo); }
  136.  void *& pword(int _Idx)
  137.   {return (_Findarr(_Idx)._Vp); }
  138. protected:
  139.  ios()
  140.   {init(0); }
  141.  ios(_Uninitialized)
  142.   {}
  143.  void init(streambuf *);
  144. private:
  145.  streambuf *_Sb;
  146.  ostream *_Tiestr;
  147.  iostate _State, _Except;
  148.  fmtflags _Fmtfl;
  149.  int _Prec, _Wide;
  150.  char _Fillch;
  151.  static int _Index;
  152.  _Iosarray *_Arr;
  153.  _Iosarray& _Findarr(int);
  154.  void _Tidy();
  155.  };
  156. _BITMASK_OPS(ios::_Fmtflags)
  157. _BITMASK_OPS(ios::_Iostate)
  158. _BITMASK_OPS(ios::_Openmode)
  159.   // manipulators
  160. ios& dec(ios&);
  161. ios& fixed(ios&);
  162. ios& hex(ios&);
  163. ios& internal(ios&);
  164. ios& left(ios&);
  165. ios& noshowbase(ios&);
  166. ios& noshowpoint(ios&);
  167. ios& noshowpos(ios&);
  168. ios& noskipws(ios&);
  169. ios& nouppercase(ios&);
  170. ios& oct(ios&);
  171. ios& right(ios&);
  172. ios& scientific(ios&);
  173. ios& showbase(ios&);
  174. ios& showpoint(ios&);
  175. ios& showpos(ios&);
  176. ios& skipws(ios&);
  177. ios& uppercase(ios&);
  178.  
  179. #if __MWERKS__
  180. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  181. #pragma import reset
  182. #endif
  183.  
  184. #pragma options align=reset
  185. #endif
  186.  
  187. #endif
  188.  
  189. /*
  190.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  191.  * Consult your license regarding permissions and restrictions.
  192.  */
  193.  
  194. /* Change log:
  195.  *94Oct03 Version received from PlumHall
  196.  *94Oct07 Inserted MW changes.
  197.  */
  198.